const express = require('express')
const cors = require('cors')//跨域解决中间件
const { expressjwt } = require('express-jwt')//改版咯，解构赋值把函数导入
const secretKey = require('./secret/secretKey.js')//密钥

const app = express()

app.use(cors())//注意用steam++ 代理会请求不到数据，还报的跨域，奇葩问题，给我整不会了
app.use(express.json())//允许Json对象解析
app.use(express.urlencoded({ extended: false }))//解析表单

//开放public文件夹下的资源(路径中不加public)
//app.use(express.static('public/dist'))

//路由配置
app.use('/api', require('./api/user/login.js'))
app.use('/api', require('./api/user/register.js'))
app.use('/api', require('./api/blog/uploadBlog.js'))
app.use('/api', require('./api/blog/uploadImage.js'))
app.use(require('./api/image/readImage.js'))//读取图片路由，不加api了
app.use('/api', require('./api/blog/getBlog.js'))
app.use('/api', require('./api/blog/queryBlog.js'))
app.use(expressjwt({secret: secretKey, algorithms: ["HS256"]}))//这里开始的路由都有登录鉴权了，没登录请求直接给挡了
app.use('/api', require('./api/user/getUserInfo.js'))
app.use('/api', require('./api/user/uploadAvatar.js'))
app.use('/api', require('./api/user/updatePassword.js'))

//启动服务器
app.listen(80, () => {
    console.log('后端服务器启动成功...')
})